package com.tim.test.leetcode.exam;


import java.util.PriorityQueue;

public class HuaWei20230619 {
    /**
     *输入：
     * China 32 28 34
     * England 12 34 22
     * France 23 33 2
     * Japan 12 34 25
     * Rusia 23 43 0
     * 输出：
     * China
     * Rusia
     * France
     * Japan
     * England
     */
    public static void main(String[] args) {
        String info = "China 32 28 34\n" +
                "England 12 34 22\n" +
                "Eingland 12 34 22\n" +
                "France 23 33 2\n" +
                "Japan 12 34 25\n" +
                "Rusia 23 43 0\n" ;
        String[] split = info.trim().split("\n+");
        // 入堆排序输出；PriorityQueue默认为小根堆
        PriorityQueue<CountryScore> priorityQueue = new PriorityQueue<>(split.length);
        for(String str : split){
            priorityQueue.add(new CountryScore(str));
        }
        while(!priorityQueue.isEmpty()){
            CountryScore poll = priorityQueue.poll();
            System.out.println(poll.country);
        }
    }

    static class CountryScore implements Comparable{
        String country;
        int goldNum;
        int silverNum;
        int cuNum;

        CountryScore(String str){
            String[] split = str.trim().split("\\s+");
            if(split.length!=4){
                throw new RuntimeException();
            }
            country = split[0];
            goldNum = Integer.valueOf(split[1]);
            silverNum = Integer.valueOf(split[2]);
            cuNum = Integer.valueOf(split[3]);
        }

        @Override
        public int compareTo(Object o) {
            CountryScore other = (CountryScore) o;
            if(this.goldNum==other.goldNum
                    && this.silverNum==other.silverNum
                    && this.cuNum==other.cuNum
                    && this.country.equals(other.country)){
                return 0;
            }
            return this.goldNum>other.goldNum ? -1
                    : this.goldNum==other.goldNum && this.silverNum>other.silverNum ? -1
                    : this.goldNum==other.goldNum && this.silverNum==other.silverNum
                        && this.cuNum>other.cuNum ? -1
                    : this.goldNum==other.goldNum && this.silverNum==other.silverNum
                        && this.cuNum==other.cuNum && this.country.compareTo(other.country)<0 ? -1
                    : 1;
        }
    }

}
